////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

namespace GatherTogether
{
    namespace GatherDrops
    {
        /// <summary>
        /// Class that contains information about the possible items aquired from
        /// a single type of resource node.
        /// 
        /// For example, from a copper node you will always get copper ore, but you
        /// might also get rough stone or a rare gem like malachite or tigerseye.
        /// </summary>
        class Node : System.Collections.Generic.IEnumerable<Loot>
        {
            protected string m_nodeId = null;
            protected System.Collections.Hashtable m_loots = new System.Collections.Hashtable();

            private Node() { }

            public Node(string nodeId)
            {
                m_nodeId = nodeId;
            }

            public string Id
            {
                get
                {
                    return m_nodeId;
                }
            }

            public System.Collections.Generic.IEnumerator<Loot> GetEnumerator()
            {
                foreach (System.Collections.DictionaryEntry entry in m_loots)
                {
                    yield return entry.Value as Loot;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public void AddLoot(Loot loot)
            {
                Loot myLoot = m_loots[loot.Id] as Loot;

                // check to see if a loot with this id already exists
                if (myLoot == null)
                {
                    // it does not, so add a new entry to the table
                    m_loots.Add(loot.Id, loot);
                }
                else
                {
                    // it does, so increment the existing table entry
                    myLoot.Count += loot.Count;
                }
            }

            // this probably doesnt work anymore, but for the time being, save as a reference
            //public override string ToString()
            //{
            //    string result = "[" + m_nodeId + "] = {" + System.Environment.NewLine;

            //    foreach (System.Collections.DictionaryEntry entry in m_loots)
            //    {
            //        result += "[" + entry.Key as string + "] = " + entry.Value + "," + System.Environment.NewLine;
            //    }

            //    result += "},";

            //    return result;
            //}
        }
    }
}
